//
//  ST_PairsCenterOnlyLoveMePecCell.swift
//  btvideo
//
//  Created by mac on 2020/9/5.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwiftyJSON
import SwiftyAttributes
import HandyJSON

// 只有喜欢我的特质
class ST_PairsCenterOnlyLoveMePecCell: UITableViewCell {
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
    
        contentView.backgroundColor = UIColor.init(hex: 0xACB4C0)
        
        contentView.addSubview(corner_radius_view)
        corner_radius_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 3, left: 0, bottom: 0, right: 0))
        }
        
        corner_radius_view.addSubview(matchValueImageView)
        matchValueImageView.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(118)
        }
        
        
        contentView.addSubview(heart_image_view)
        heart_image_view.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.height.equalTo(58)
            make.top.equalToSuperview().offset(15)
        }
        
        contentView.addSubview(value_label)
        value_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
            make.top.equalToSuperview().offset(83)
        }
        
        contentView.addSubview(likeMeItemView)
        likeMeItemView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(matchValueImageView.snp.bottom)
            make.height.equalTo(100)
        }
        
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    fileprivate lazy var value_label:UILabel = {
       let control = UILabel()
        return control
    }()
    
    
    fileprivate lazy var heart_image_view:UIImageView = {
       let control = UIImageView()
        control.image = ST_ImageUtils.imageName("peculiarity_value_heart_icon")
        return control
    }()
    
    fileprivate lazy var matchValueImageView:UIImageView = {
       let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("peculiarity_match_value_icon_top")
        control.clipsToBounds = true
        return control
    }()
    
    fileprivate lazy var corner_radius_view:UIView = {
        let control = UIView()
        control.backgroundColor = Color.white
        control.cornerRadius = 30
        return control
    }()
    
    fileprivate lazy var likeMeItemView:PairsCenterPeculiaritySectionView = {
       let control = PairsCenterPeculiaritySectionView()
        return control
    }()
    
    
    var model:ST_PairsCenterOnlyLoveMePecCellModel?{
        didSet{
            
            guard let m = model else { return }
            
            value_label.attributedText = m.matchNumberStr
            
            likeMeItemView.snp.updateConstraints { (make) in
                make.height.equalTo(m.loveMeArrayHeight)
            }
            
            likeMeItemView.model_list = m.loveMeArray
            
            likeMeItemView.title = m.genderStr + "喜欢我的特质"
        }
    }
    
}

//MARK: - Model
class ST_PairsCenterOnlyLoveMePecCellModel: NSObject,ST_CellTypeProtocol {
    
    var cellType: ST_PairsCenterCellType = .onlyLoveMePeculiarity
    
    var pairsCellHeight: CGFloat = 100
    
    var loveMeArray:[ST_PairsPeculiarity]
    
    var loveMeArrayHeight = 0.cgFloat
    
    var matchInfo:PairsMatchInfo
    
    var genderStr:String
//    ex:她喜欢4个你的特质
    var matchNumberStr = NSAttributedString()
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON,gender:String){
    
        genderStr = gender
        
        loveMeArray = json["target_like_i_have"].arrayValue.map { (itemJson) -> ST_PairsPeculiarity in
            return ST_PairsPeculiarity.deserialize(from: itemJson.rawString() ?? "") ?? ST_PairsPeculiarity()
        }
        
        matchInfo = PairsMatchInfo.init(fromJson: json["match_info"])
        
        super.init()
        
        //她喜欢4个你的特质
        
        matchNumberStr = "\(gender)喜欢".withAttributes([Attribute.textColor(Color.white),Attribute.font(Font.systemFont(ofSize: 14, weight: UIFont.Weight.semibold))]) + matchInfo.targetLikeIHaveCount.string.withAttributes([Attribute.textColor(Color.init(hex: 0xFF1F56)!),Attribute.font(Font.systemFont(ofSize: 14, weight: UIFont.Weight.semibold))]) + "个你的特质".withAttributes([Attribute.textColor(Color.white),Attribute.font(Font.systemFont(ofSize: 14, weight: UIFont.Weight.semibold))])
        
        
        loveMeArrayHeight = PairsCenterPeculiaritySectionView.getHeight(itemCount: loveMeArray.count)
      
        
         pairsCellHeight = loveMeArrayHeight + 25 + 118
        
    }
    
}
